package cn.com.huzo.common.web.listener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;

/**
 * Session事件监听器
 * <p>
 * @author 吴旭
 */
public class HuzoSessionListener implements SessionListener {

    protected final Log logger = LogFactory.getLog(HuzoSessionListener.class);

    //@Resource(name = "MembershipManager")
    //private IdentityUserManager _manager;
    /**
     * 创建
     * <p>
     * @param session
     */
    @Override
    public void onStart(Session session) {
        logger.info("Session start ...");
    }

    /**
     * 停止
     * <p>
     * @param session
     */
    @Override
    public void onStop(Session session) {
        logger.info("Session stop ...");
        //String _username = session.getAttribute("DefaultSubjectContext_PRINCIPALS_SESSION_KEY").toString();
        try {
            //_manager.UpdateUserOnLineStatus(_username, 0);
        } catch (Exception ex) {
            logger.info(ex.getMessage());
        }
    }

    /**
     * 过期
     * <p>
     * @param session
     */
    @Override
    public void onExpiration(Session session) {
        // org.apache.shiro.subject.suppor
        //String _username = session.getAttribute("DefaultSubjectContext_PRINCIPALS_SESSION_KEY").toString();
        try {
            //_manager.UpdateUserOnLineStatus(_username, 0);
        } catch (Exception ex) {
            logger.info(ex.getMessage());
        }
    }
}
